package my.spring.aop;

import my.spring.aop.annotation.Aop;
import my.spring.aop.aspect.Advisor;
import my.spring.ioc.AnnotationBeanFactory;
import my.spring.ioc.bean.BeanDefinition;

/**
 * BeanFactory注解实现类
 * @author fengbo
 * @date 2018/3/20
 */
public class AnnotationProxyBeanFactory extends AnnotationBeanFactory {

    @Override
    public Object getBean(String beanName) {
        Object bean = super.getBean(beanName);
        BeanDefinition beanDefinition = getBeanDefinition(beanName);
        if (beanDefinition.isProxy()) {
            Advisor advisor = (Advisor) beanMap.get("advisor");
            bean = new ProxyFactory(bean, advisor).getProxy();
        }
        return bean;
    }
}
